package com.tech.connect.api;

import android.text.TextUtils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ImageApi {
    private static Map<Integer, String> set;

    static {
        set = new HashMap<>();
        set.put(0, "http://pic1.16pic.com/00/04/78/16pic_478386_b.jpg");
        set.put(1, "http://pic29.photophoto.cn/20131020/0034034826601136_b.jpg");
        set.put(2, "http://pic.58pic.com/58pic/13/71/22/35T58PICrEk_1024.jpg");
        set.put(3, "http://pic.58pic.com/58pic/13/71/06/63J58PIC2FC_1024.jpg");
        set.put(4, "http://pic17.nipic.com/20111022/8575840_114126243000_2.jpg");
        set.put(5, "http://pic.58pic.com/58pic/11/31/79/05B58PICvtS.jpg");
        set.put(6, "https://up.enterdesk.com/edpic_source/c6/08/b9/c608b93a685af8e8d3dac2aac7f12b02.jpg");
        set.put(7, "http://pic35.photophoto.cn/20150609/0034034813658910_b.jpg");
    }

    public static String getImageParams(List<String> images) {
        StringBuilder stringBuilder = new StringBuilder();
        for (int i = 0; i < images.size(); i++) {
            String s = images.get(i);
            stringBuilder.append(s);
            if (i != images.size() - 1) {
                stringBuilder.append(";");
            }
        }
        return stringBuilder.toString();
    }

    public static ArrayList<String> getImages(String images) {
        ArrayList<String> imageList = new ArrayList<>();
        if (TextUtils.isEmpty(images)) {
            return imageList;
        }
        if (images.contains(";")) {
            String[] split = images.split(";");
            List<String> strings = Arrays.asList(split);
            imageList.addAll(strings);
        } else {
            imageList.add(images);
        }
        return imageList;
    }

    public static String getImage(String images) {
        if (TextUtils.isEmpty(images)) {
            return "";
        }
        if (!images.contains(";")) {
            return images;
        }
        if (images.contains(";")) {
            String[] split = images.split(";");
            if (split.length > 0) {
                return split[0];
            }
        }
        return "";
    }
}
